package edu.study.api.common.dto;

import com.fasterxml.jackson.annotation.JsonIgnore;
import edu.study.api.common.enums.BaseResultCodeEnum;
import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class BaseRespDto extends BaseDto {
    /**
	 * 
	 */
	private static final long serialVersionUID = -4090274360330489545L;

	/**
     * 业务应答码,每个接口实现自己定义
     */
    private String resultCode;

    /**
     * 业务应答信息,每个接口实现自己定义
     */
    private String resultMessage;

    //默认成功
    public BaseRespDto() {
        this.setResultSuccess();
    }

    @JsonIgnore
    public boolean isSuccess() {
        return BaseResultCodeEnum.SUCCESS.getCode().equals(this.resultCode);
    }

	public BaseRespDto setResult(String code, String message) {
        this.resultCode = code;
        this.resultMessage = message;
        return this;
    }

	public BaseRespDto setResultSuccess() {
        this.resultCode = BaseResultCodeEnum.SUCCESS.getCode();
        this.resultMessage = BaseResultCodeEnum.SUCCESS.getMessage();
        return this;
    }

	public BaseRespDto setResultFail() {
        this.resultCode = BaseResultCodeEnum.FAIL.getCode();
        this.resultMessage = BaseResultCodeEnum.FAIL.getMessage();
        return this;
    }

	public BaseRespDto setResultException() {
        this.resultCode = BaseResultCodeEnum.EXCEPTION.getCode();
        this.resultMessage = BaseResultCodeEnum.EXCEPTION.getMessage();
        return this;
    }

    public void setResultSuccess(String message) {
        this.resultCode = BaseResultCodeEnum.SUCCESS.getCode();
        this.resultMessage = message;
    }

	public BaseRespDto setResultFail(String message) {
        this.resultCode = BaseResultCodeEnum.FAIL.getCode();
        this.resultMessage = message;
        return this;
    }

	public BaseRespDto setResultException(String message) {
        this.resultCode = BaseResultCodeEnum.EXCEPTION.getCode();
        this.resultMessage = message;
        return this;
    }

    public void setResultFail(BaseResultCodeEnum result){
        this.resultCode = result.getCode();
        this.resultMessage = result.getMessage();
    }

    public BaseRespDto setResultProcessing(String message) {
        this.resultCode = BaseResultCodeEnum.PROCESSING.getCode();
        this.resultMessage = message;
        return this;
    }

    public BaseRespDto setResultBizException(String message) {
        this.resultCode = BaseResultCodeEnum.BIZ_EXCEPTION.getCode();
        this.resultMessage = message;
        return this;
    }
}
